/*
 * Copyright (c) 2020 IUV Inc. All rights reserved.
 * 项目名称：IUV TXY
 * 文件名：ImRequsetUtil.java
 * Date：20-10-22 下午5:15
 * Author：Will
 */

package com.iuv.imdemo.util;

import com.alibaba.fastjson.JSONObject;
import com.iuv.config.ImSetting;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.web.client.RestTemplate;

/**
 * IM服务请求工具类
 *
 * @author Will
 * @date 17:15
 */
public class ImRequsetUtil {
    private final static String BASE_IM_URL="https://console.tim.qq.com/";
    public static JSONObject request(String requestUrl,String usersig,String requestDataJson)
    {
        RestTemplate restTemplate=new RestTemplate();
        StringBuilder stringBuilder=new StringBuilder();
        stringBuilder.append(BASE_IM_URL);
        stringBuilder.append(requestUrl);
        stringBuilder.append("?sdkappid="+ ImSetting.SDK_APP_ID);
        stringBuilder.append("&identifier=");
        stringBuilder.append(ImSetting.IDENTIFIER);
        stringBuilder.append("&usersig=");
        stringBuilder.append(usersig);
        stringBuilder.append("&random=");
        stringBuilder.append(RandomUtils.nextInt());
        stringBuilder.append("&contenttype=json");
        return restTemplate.postForObject(stringBuilder.toString(),requestDataJson,JSONObject.class);
    }
}
